clear all
set more off
set scheme s1mono
cd "~/BHVM_Replication/"
* ssc install tabplot

*load the data
use "Mturk/MTurkReplication.dta", clear
cd "~/BHVM_Replication/Code/Results/"

*drop if Member not still in Congress
drop if apiAH_2=="Allyson Schwartz"
drop if apiAH_2=="Bill Cassidy"
drop if apiAH_2=="Bill Enyart"
drop if apiAH_2=="Bill Owens"
drop if apiAH_2=="Bill Young"
drop if apiAH_2=="Brad Schneider"
drop if apiAH_2=="Bruce Braley"
drop if apiAH_2=="Carol Shea-Porter"
drop if apiAH_2=="Carolyn McCarthy"
drop if apiAH_2=="Colleen Hanabusa"
drop if apiAH_2=="Cory Gardner"
drop if apiAH_2=="Dan Maffei"
drop if apiAH_2=="Dave Camp"
drop if apiAH_2=="Doc Hastings"
drop if apiAH_2=="Donna Christensen"
drop if apiAH_2=="Ed Pastor"
drop if apiAH_2=="Edward Markey"
drop if apiAH_2=="Eni Faleomavaega"
drop if apiAH_2=="Eric Cantor"
drop if apiAH_2=="Frank Wolf"
drop if apiAH_2=="Gary Miller"
drop if apiAH_2=="Gary Peters"
drop if apiAH_2=="Gary Peters"
drop if apiAH_2=="George Miller"
drop if apiAH_2=="Gloria McLeod"
drop if apiAH_2=="Henry Waxman"
drop if apiAH_2=="Howard Buck"
drop if apiAH_2=="Howard Coble"
drop if apiAH_2=="Jack Kingston"
drop if apiAH_2=="James Lankford"
drop if apiAH_2=="James Lankford"
drop if apiAH_2=="James Moran"
drop if apiAH_2=="Jim Gerlach"
drop if apiAH_2=="Jim Matheson"
drop if apiAH_2=="Jo Bonner"
drop if apiAH_2=="Jo Emerson"
drop if apiAH_2=="Joe Garcia"
drop if apiAH_2=="John Barrow"
drop if apiAH_2=="John Campbell"
drop if apiAH_2=="John Dingell"
drop if apiAH_2=="John Tierney"
drop if apiAH_2=="Jon Runyan"
drop if apiAH_2=="Kerry Bentivolio"
drop if apiAH_2=="Lee Terry"
drop if apiAH_2=="Melvin Watt"
drop if apiAH_2=="Michael Grimm."
drop if apiAH_2=="Michael Michaud"
drop if apiAH_2=="Michele Bachmann"
drop if apiAH_2=="Mike McIntyre"
drop if apiAH_2=="Mike Rogers"
drop if apiAH_2=="Nick Rahall"
drop if apiAH_2=="Paul Broun"
drop if apiAH_2=="Pete Gallego"
drop if apiAH_2=="Phil Gingrey"
drop if apiAH_2=="Ralph Hall"
drop if apiAH_2=="Robert Andrews"
drop if apiAH_2=="Rodney Alexander"
drop if apiAH_2=="Ron Barber"
drop if apiAH_2=="Rush Holt"
drop if apiAH_2=="Shelley Moore"
drop if apiAH_2=="Shelley Moore"
drop if apiAH_2=="Spencer Bachus"
drop if apiAH_2=="Steve Daines"
drop if apiAH_2=="Steve Daines"
drop if apiAH_2=="Steve Southerland"
drop if apiAH_2=="Steve Stockman"
drop if apiAH_2=="Steven Horsford"
drop if apiAH_2=="Tim Griffin"
drop if apiAH_2=="Tim Scott"
drop if apiAH_2=="Timothy Bishop"
drop if apiAH_2=="Tom Cotton"
drop if apiAH_2=="Tom Cotton"
drop if apiAH_2=="Tom Latham"
drop if apiAH_2=="Tom Petri"
drop if apiAH_2=="Trey Radel"
drop if apiAH_2=="Vance McAllister"
drop if apiAH_2==""
drop if apiAH_2=="Aaron Schock"
drop if apiAH_2=="John Boehner"
drop if apiAH_2=="Michael Grimm"
drop if apiAH_2=="Alan Nunelee"

*CODE META VARIABLES
*create a dummy for effectiveness information treatment (called efinfo)
gen efinfo=0
replace efinfo=1 if rand13==3
replace efinfo=1 if rand13==4
label var efinfo "1 = Treatment, received effetiveness information"

*create indicator variables for R's representative's true effectiveness
gen effective=0
replace effective=1 if apiAH_5=="Highly Effective"
label var effective "1 = Actually highly effective"
gen ineffective=0
replace ineffective=1 if apiAH_5=="Not Effective"
label var ineffective "1 = Actually ineffective"
gen avgeffective=0
replace avgeffective=1 if apiAH_5=="Average in Effectiveness"
label var avgeffective "1 = Actually average in effectiveness"

*code r's subjective effectiveness evaluations (POST TREATMENT)
gen r_effective=0
replace r_effective=1 if lesrecall==1 
label var r_effective "1 = Perceived highly effective"
gen r_ineffective=0
replace r_ineffective=1 if lesrecall==3
label var r_ineffective "1 = Perceived ineffective"
gen r_avgeffective=0
replace r_avgeffective=1 if lesrecall==2
label var r_avgeffective "1 = Perceived average in effectiveness"

*CODE KEY EXPLANATORY VARIABLES
*Interaction Version
gen effinteract=effective*efinfo
label var effinteract "1 = Treatment and actually highly effective"
gen ineffinteract=ineffective*efinfo
label var ineffinteract "1 = Treatment and actually ineffective"

*CODE RESPONDENT DEMOGRAPHICS
*code ideology
gen lib=0
replace lib=1 if ideology==1 | ideology==2 | ideology==3
label var lib "1 = anywhere on liberal end of scale, non-moderate"
gen con=0
replace con=1 if ideology==5 | ideology==6 | ideology==7
label var con "1 = anywhere on conservative end of scale, non-moderate"

*code partisanship
gen rep=0
replace rep=1 if anes_pid=="1"
	*include leaners
replace rep=1 if anes_pidi==1
label var rep "1 = Republican, including leaners"
gen dem=0
replace dem=1 if anes_pid=="2"
	*include leaners
replace dem=1 if anes_pidi==2
label var dem "1 = Democrat, including leaners"

gen copartisan=.
replace copartisan=1 if dem==1 &apiAH_3=="Democrat"
replace copartisan=1 if rep==1 &apiAH_3=="Republican"
replace copartisan=0 if rep==1 &apiAH_3=="Democrat"
replace copartisan=0 if dem==1 &apiAH_3=="Republican"
label var copartisan "1 = Respondent and Representative in same party"

*code rep party for each respondent
gen rdem=0 
replace rdem=1 if apiAH_3=="Democrat"
label var rdem "1 = Representative is a Democrat"
gen rrep=0  
replace rrep=1 if apiAH_3=="Republican"
label var rrep "1 = Representative is a Republican"

gen trueeff=.
replace trueeff=0 if ineffective==1
replace trueeff=1 if avgeffective==1
replace trueeff=2 if effective==1
label var trueeff "0 = actual ineffective, 1 = actual average, 2 = actual highly effective"

	gen true_eff2=3-trueeff /*Do this to ensure that we actually have it in same scale as perceived effectiveness (lesrecall)*/

*CREATE KEY DEPENDENT VARIABLES
gen voteforrep=0
replace voteforrep=1 if voteintent==1
replace voteforrep=1 if voteintent==2
label var voteforrep "1 = intend to vote for incumbent"

gen approve=0
replace approve=1 if approvedisapprove==1
replace approve=1 if approvedisapprove==2
replace approve=0 if approvedisapprove==3
replace approve=0 if approvedisapprove==4
label var approve "1 = Approve or strongly approve job of incumbent"

*4 category approval
gen approve4=0
replace approve4=0 if approvedisapprove==4
replace approve4=.333 if approvedisapprove==3
replace approve4=.666 if approvedisapprove==2
replace approve4=1 if approvedisapprove==1
label var approve4 "Four category job approval"

/*
*check balance
ttest effective,by(efinfo)
ttest avgeffective,by(efinfo)
ttest ineffective,by(efinfo)
ttest dem,by(efinfo)
ttest lib,by(efinfo)
ttest rep,by(efinfo)
ttest con,by(efinfo)
ttest age,by(efinfo)
ttest education,by(efinfo)
ttest income,by(efinfo)
ttest gender,by(efinfo)

egen thermevals01 = std01(thermevals_1)
gen voteforrep01=.
replace voteforrep01=1 if voteintent==1
replace voteforrep01=.75 if voteintent==2
replace voteforrep01=.25 if voteintent==3
replace voteforrep01=0 if voteintent==4
*/


*********************
*********************
******ANALYSIS*******
*********************
*********************

** Outcome = Approve of MC

** Basic Levels of Knowledge in Control Group (For Figure 1 in Paper)
	tab lesrecall true_eff2 if efinfo==0, chi
	corr  lesrecall true_eff2 if efinfo==0
	tabplot lesrecall trueeff if efinfo==0, percent(trueeff)  horizontal ytitle("Perceived" "Effectiveness") ylab(1 "Ineffective" 2 "Average" 3 "Highly Effective") xtitle( " " "Actual Effectiveness") xlabel(1 "Ineffective" 2 "Average" 3 "Highly Effective") showval(format(%2.1f) mlabsize(vsmall) offset(0.25)) title("MTurk Survey (Control Group)", size(medium)) subtitle(" ")
		graph save knowledge_mturk.gph, replace 
	

** Relationship between approval and actual/perceived Effectiveness in Control Group (for Figure 2 in Paper)
	bysort trueeff: egen perc_approve_true=mean(approve) if efinfo==0
	bysort lesrecall: egen perc_approve_perceived=mean(approve) if efinfo==0
	graph bar (mean) perc_approve_true, ylabel(0(.2)1) over(trueeff, relabel(1"Ineffective" 2 "Average" 3 "Highly Effective")) ytitle(Percent Approving of Legislator) title("MTurk, Actual Effectiveness") 
		graph save approve_actual_mturk.gph, replace 
		
		gen l2=4-lesrecall /*Create this in order to get scale right on graph*/
	graph bar (mean) perc_approve_perceived if efinfo==0, ylabel(0(.2)1) over(l2, relabel(1"Ineffective" 2 "Average" 3 "Highly Effective")) ytitle(Percent Approving of Legislator) title("MTurk, Perceived Effectiveness")
		graph save approve_perceived_mturk.gph, replace 

*************************************
** Figure 4: Main Treatment Effect **
*************************************

** Results in Paper
	reg approve efinfo if effective==1
	est store Effective

	reg approve efinfo if avgeffective==1
	est store Avg_Effective

	reg approve efinfo if ineffective==1 
	est store Ineffective
	#delimit;
	coefplot (Effective, drop(_cons) mcol(green) label(Highly Effective)) (Avg_Effective, drop(_cons) mcol(black) label(Average)) 
	(Ineffective, drop(_cons) mcol(red)),  ylabel("") title("MTurk, Approval of Lawmaker, Treatment Effects", size(medium)) 
	 legend(row(1) order(6 4 2)) 
	 xlabel (-.4 "-.4" -.2 "-.2" 0 "0" .2 ".2" .4 ".4" -.3 `"" " "Lower Approval""'  .3`"" "  "Higher Approval""', noticks)
	xtitle(Effect of Effectiveness Information on Approval of their Lawmaker);
	 #delimit cr
		graph save "MainTreatment_Mturk.gph", replace
		
** Appendix
	logit approve efinfo if effective==1
	margins, at(efinfo=(0(1)1)) post
	est store Effective

	logit approve efinfo if avgeffective==1
	margins, at(efinfo=(0(1)1)) post
	est store Avg_Effective

	logit approve efinfo if ineffective==1 
	margins, at(efinfo=(0(1)1)) post
	est store Ineffective

	coefplot (Effective, mcol(green) label(Highly Effective)) (Avg_Effective, mcol(black) label(Average)) (Ineffective, mcol(red)),  ylabel(`=1' "Control" `=2' "Treated") title("MTurk, Approval of Lawmaker", size(medium)) 	legend(row(1) order(6 4 2)) 	
		graph save "MainTreatment_Mturk_Appendix.gph", replace


******************************************************************
** Figure 5: Heterogeneous Treatment Effects, by copartisanship **
******************************************************************

** Results in Paper
	reg approve efinfo if effective==1 & copartisan==1
		est store E1
	reg approve efinfo if effective==1 & copartisan==0
		est store E2
		
	reg approve efinfo if avgeffective==1 & copartisan==1
		est store A1
	reg approve efinfo if avgeffective==1 & copartisan==0
		est store A2

	reg approve efinfo if ineffective==1 & copartisan==1
		est store I1
	reg approve efinfo if ineffective==1 & copartisan==0
		est store I2

	coefplot (E1, drop(_cons) mcol(green) msymbol(O) label(Highly Effective)) (A1, drop(_cons) mcol(black) msymbol(D)  label(Average)) (I1, drop(_cons) mcol(red) msymbol(S)  label(Ineffective))   (E2, drop(_cons) mcol(green) msymbol(O) label(Highly Effective)) (A2, drop(_cons) mcol(black) msymbol(D) label(Average)) (I2, drop(_cons) mcol(red) msymbol(S) label(Ineffective)),  ylabel("")  title("MTurk Approval, by Partisan Alignment")  ylabel(.8 "Copartisan" 1.2 "Outparty") legend(row(1) order(6 4 2)) xlabel (-.4 "-.4" -.2 "-.2" 0 "0" .2 ".2" .4 ".4" -.3 `"" " "Lower Approval""'  .3`"" "  "Higher Approval""', noticks) xtitle(Effect of Effectiveness Information on Approval of their Lawmaker)
		graph save "Partisanship_MTurk.gph", replace
	
** Appendix
	logit approve copartisan##efinfo if effective==1 
		margins, at(efinfo=(0(1)1) copartisan=(0(1)1)) post
		est store Effective
	
	logit approve copartisan##efinfo if avgeffective==1
		margins, at(efinfo=(0(1)1) copartisan=(0(1)1)) post
		est store Avg_Effective

	logit approve copartisan##efinfo if ineffective==1 
		margins, at(efinfo=(0(1)1) copartisan=(0(1)1)) post
		est store Ineffective

	coefplot (Effective, mcol(green) label(Highly Effective)) (Avg_Effective, mcol(black) label(Average)) (Ineffective, mcol(red)),  ylabel(`=1' "Outparty, Control" `=2' "Outparty, Treated" `=3' "Copartisan, Control" `=4' "Copartisan, Treated")  title("MTurk Approval, by Partisan Alignment") legend(row(1) order(6 4 2))
		graph save "Partisanship_MTurk_Appendix.gph", replace

	
************************************************************
** Figure 6: Heterogenenous treatment effects by ideology **
************************************************************

*Create ideological extremism indicator
gen extreme=0
replace extreme=1 if ideology==1 | ideology==2 | ideology==6 | ideology==7
label var extreme "1 = Self identified as Very Liberal, Liberal, Conservative, or Very Conservative"

** Results in Paper
	reg approve efinfo if effective==1 & extreme==1
		est store E1
	reg approve efinfo if effective==1 & extreme==0
		est store E2
		
	reg approve efinfo if avgeffective==1 & extreme==1
		est store A1
	reg approve efinfo if avgeffective==1 & extreme==0
		est store A2

	reg approve efinfo if ineffective==1 & extreme==1
		est store I1
	reg approve efinfo if ineffective==1 & extreme==0
		est store I2

	coefplot (E1, drop(_cons) mcol(green) msymbol(O) label(Highly Effective)) (A1, drop(_cons) mcol(black) msymbol(D)  label(Average)) (I1, drop(_cons) mcol(red) msymbol(S)  label(Ineffective))   (E2, drop(_cons) mcol(green) msymbol(O) label(Highly Effective)) (A2, drop(_cons) mcol(black) msymbol(D) label(Average)) (I2, drop(_cons) mcol(red) msymbol(S) label(Ineffective)),  ylabel("")  title("MTurk Approval, by Ideological Extermism") legend(row(1) order(6 4 2)) ylabel(.8 "Extreme" 1.2 "Moderate") xlabel (-.4 "-.4" -.2 "-.2" 0 "0" .2 ".2" .4 ".4" -.3 `"" " "Lower Approval""'  .3`"" "  "Higher Approval""', noticks) xtitle(Effect of Effectiveness Information on Approval of their Lawmaker)
		graph save "IdeologicalExtremism_MTurk.gph", replace

** Appendix
logit approve extreme##efinfo if effective==1 
		margins, at(efinfo=(0(1)1) extreme=(0(1)1)) post
		est store Effective
	
	logit approve extreme##efinfo if avgeffective==1
		margins, at(efinfo=(0(1)1) extreme=(0(1)1)) post
		est store Avg_Effective

	logit approve extreme##efinfo if ineffective==1 
		margins, at(efinfo=(0(1)1) extreme=(0(1)1)) post
		est store Ineffective

	coefplot (Effective, mcol(green) label (Highly Effective)) (Avg_Effective, mcol(black) label (Average)) (Ineffective, mcol(red)),  ylabel(`=1' "Moderate, Control" `=2' "Moderate, Treated" `=3' "Extreme, Control" `=4' "Extreme, Treated")  title("MTurk Approval, by Ideological Extremism") legend(row(1) order(6 4 2))
		graph save "IdeologicalExtremism_MTurk_Appendix.gph", replace

				
*************
*************	
**  Aside  **
*************
*************


** Do Copartisans Update differently? (See interaction term)
	*Generate predictor for correctly identifying their effectiveness
		gen correcteval=true_eff2==lesrecall if lesrecall!=.
	*Models	
		logit correcteval copartisan##efinfo if effective==1  		
		logit correcteval copartisan##efinfo if ineffective==1  		
		
*****************
*****************	
**   Appendix  **
**   Figures   **
*****************
*****************

	** Relationship between voting and actual/perceived Effectiveness
	bysort trueeff: egen perc_vote_true=mean(voteforrep) if efinfo==0
	bysort lesrecall: egen perc_vote_perceived=mean(voteforrep) if efinfo==0
	graph bar (mean) perc_vote_true, ylabel(0(.2)1) over(trueeff, relabel(1"Ineffective" 2 "Average" 3 "Highly Effective")) ytitle(Probability of Voting for Legislator) title("MTurk (Control), Actual Effectiveness") 
		graph save vote_actual_mturk.gph, replace 
		
		*gen l2=4-lesrecall /*Create this in order to get scale right on graph*/
	graph bar (mean) perc_vote_perceived, ylabel(0(.2)1) over(l2, relabel(1"Ineffective" 2 "Average" 3 "Highly Effective")) ytitle(Probability of Voting for Legislator) title("MTurk (Control), Perceived Effectiveness")
		graph save vote_perceived_mturk.gph, replace 


	** Main Treatment Effect - Vote Intention (For Figure A1 in Paper)
	logit voteforrep efinfo if effective==1
		margins, at(efinfo=(0(1)1)) post
		est store Effective

	logit voteforrep efinfo if avgeffective==1
		margins, at(efinfo=(0(1)1)) post
		est store Avg_Effective

	logit voteforrep efinfo if ineffective==1 
		margins, at(efinfo=(0(1)1)) post
		est store Ineffective

	coefplot (Effective, mcol(green) label(Highly Effective)) (Avg_Effective, mcol(black) label(Average)) (Ineffective, mcol(red)),  ylabel(`=1' "Control" `=2' "Treated") title("MTurk, Intention to Reelect Lawmaker", size(medium)) legend(row(1) order(6 4 2))
		graph save "MainTreatment_Mturk_vote.gph", replace


** Heterogeneous treatment effects by copartisanship (For Figure A2 in Paper)
	logit voteforrep copartisan##efinfo if effective==1  
		margins, at(efinfo=(0(1)1) copartisan=(0(1)1)) post
	est store Effective

	logit voteforrep copartisan##efinfo if avgeffective==1 
		margins, at(efinfo=(0(1)1) copartisan=(0(1)1)) post
	est store Avg_Effective

	logit voteforrep copartisan##efinfo if ineffective==1  
		margins, at(efinfo=(0(1)1) copartisan=(0(1)1)) post
	est store Ineffective

	logit voteforrep efinfo if copartisan==1 & ineffective==1
	ttest voteforrep if copartisan==1 & ineffective==1, by(efinfo)
	
	coefplot (Effective, mcol(green) label(Highly Effective)) (Avg_Effective, mcol(black) label(Average)) (Ineffective, mcol(red)),  ylabel(`=1' "Outparty, Control" `=2' "Outparty, Treated" `=3' "Copartisan, Control" `=4' "Copartisan, Treated") title("MTurk Reelection, by Partisan Alignment", size(medium)) legend(row(1) order(6 4 2))
		graph save "Partisanship_MTurk_vote.gph", replace
		

** Heterogenenous treatment effects by ideology (for Figure A3 in Paper)

	logit voteforrep extreme##efinfo if effective==1 
		margins, at(efinfo=(0(1)1) extreme=(0(1)1)) post
		est store Effective
	
	logit voteforrep extreme##efinfo if avgeffective==1
		margins, at(efinfo=(0(1)1) extreme=(0(1)1)) post
		est store Avg_Effective

	logit voteforrep extreme##efinfo if ineffective==1 
		margins, at(efinfo=(0(1)1) extreme=(0(1)1)) post
		est store Ineffective

	coefplot (Effective, mcol(green) label (Highly Effective)) (Avg_Effective, mcol(black) label (Average)) (Ineffective, mcol(red)),  ylabel(`=1' "Moderate, Control" `=2' "Moderate, Treated" `=3' "Extreme, Control" `=4' "Extreme, Treated")  title("MTurk Reelection, by Ideological Extremism") legend(row(1) order(6 4 2))
		graph save "IdeologicalExtremism_MTurk_vote.gph", replace


************************
************************	
**      Appendix      **
**       Tables       **
************************
************************

** Appendix table A1
reg approve efinfo if effective==1
reg approve efinfo if avgeffective==1
reg approve efinfo if ineffective==1

** Appendix table A2
logit approve efinfo if effective==1
logit approve efinfo if avgeffective==1
logit approve efinfo if ineffective==1

** Appendix table A5
reg approve efinfo if effective==1  & copartisan==1
reg approve efinfo if effective==1  & copartisan==0
reg approve efinfo if avgeffective==1  & copartisan==1
reg approve efinfo if avgeffective==1  & copartisan==0
reg approve efinfo if ineffective==1  & copartisan==1
reg approve efinfo if ineffective==1  & copartisan==0

** Appendix table A6
logit approve copartisan##efinfo if effective==1  
logit approve copartisan##efinfo if avgeffective==1  
logit approve copartisan##efinfo if ineffective==1  
	
** Appendix table A9
reg approve efinfo if extreme==1 & effective==1
reg approve efinfo if extreme==0 & effective==1
reg approve efinfo if extreme==1 & avgeffective==1
reg approve efinfo if extreme==0 & avgeffective==1
reg approve efinfo if extreme==1 & ineffective==1
reg approve efinfo if extreme==0 & ineffective==1

** Appendix table A10
logit approve extreme##efinfo if effective==1  
logit approve extreme##efinfo if avgeffective==1  
logit approve extreme##efinfo if ineffective==1  

** Appendix table A13
reg approve4 efinfo if effective==1
reg approve4 efinfo if avgeffective==1
reg approve4 efinfo if ineffective==1

** Appendix table A15
reg approve4 efinfo if effective==1  & copartisan==1
reg approve4 efinfo if effective==1  & copartisan==0
reg approve4 efinfo if avgeffective==1  & copartisan==1
reg approve4 efinfo if avgeffective==1  & copartisan==0
reg approve4 efinfo if ineffective==1  & copartisan==1
reg approve4 efinfo if ineffective==1  & copartisan==0
 
 ** Appendix table A17
reg approve4 efinfo if extreme==1 & effective==1
reg approve4 efinfo if extreme==0 & effective==1
reg approve4 efinfo if extreme==1 & avgeffective==1
reg approve4 efinfo if extreme==0 & avgeffective==1
reg approve4 efinfo if extreme==1 & ineffective==1
reg approve4 efinfo if extreme==0 & ineffective==1
 
